

class my_monitor extends uvm_monitor;
   //virtual my_if vif;
   `uvm_component_utils(my_monitor)

   uvm_blocking_put_port#(my_transaction) info_data_put_port;

   function new(string name = "my_monitor", uvm_component parent = null);
      super.new(name, parent);
   endfunction

   virtual function void build_phase(uvm_phase phase);
      super.build_phase(phase);

      info_data_put_port = new("info_data_put_port", this);
      // if(!uvm_config_db#(virtual my_if)::get(this, "", "vif", vif))
      //    `uvm_fatal("my_monitor", "virtual interface must be set for vif!!!")
   endfunction
   extern task main_phase(uvm_phase phase);
   extern task collect_one_pkt(my_transaction tr);
endclass
task my_monitor::main_phase(uvm_phase phase);
   my_transaction tr;
   while(1) begin
      tr = new("tr");
      collect_one_pkt(tr);
   end
endtask
task my_monitor::collect_one_pkt(my_transaction tr);

   @(negedge top_tb.polar_enc_start);
   tr.polar_enc_data_in = top_tb.polar_enc_data_in;
   `uvm_info("my_monitor", "end collect one pkt, print it:", UVM_LOW);

   info_data_put_port.put(tr);

   // bit [47:0][7:0] data_q;
   // int i;
   // while(1) begin
   //   @(posedge vif.clk);
   //   if(vif.valid) break;
   // end
   // `uvm_info("my_monitor", "begin to collect one pkt", UVM_LOW);

   // int i = 0;
   // while(vif.valid) begin
   //    data_q[i] = //todo
   //    i ++;
   //    @(posedge vif.clk);
   // end

   // `uvm_info("my_monitor", "end collect one pkt, print it:", UVM_LOW);
   //tr.my_print();
endtask



class my_monitor_out extends uvm_monitor;

   my_transaction_code queue_code[$];
   //virtual my_if vif;
   `uvm_component_utils(my_monitor_out)

   uvm_blocking_get_imp#(my_transaction_code, my_monitor_out) code_data_get_imp;

   function new(string name = "my_monitor_out", uvm_component parent = null);
      super.new(name, parent);
   endfunction
   virtual function void build_phase(uvm_phase phase);
      super.build_phase(phase);

      code_data_get_imp = new("code_data_get_imp", this);
      // if(!uvm_config_db#(virtual my_if)::get(this, "", "vif", vif))
      //    `uvm_fatal("my_monitor_out", "virtual interface must be set for vif!!!")
   endfunction

   extern task main_phase(uvm_phase phase);
   extern task collect_one_pkt(my_transaction_code tr);
   extern task get(output my_transaction_code tr);
endclass

task my_monitor_out::get(output my_transaction_code tr);
   while(queue_code.size() == 0)begin
      #2 ;
   end
   //tr = new("tr");
   tr = queue_code.pop_front();

endtask

task my_monitor_out::main_phase(uvm_phase phase);
   my_transaction_code tr;
   while(1) begin
      tr = new("tr");
      collect_one_pkt(tr);
   end
endtask

task my_monitor_out::collect_one_pkt(my_transaction_code tr);

   @(posedge top_tb.polar_enc_done);
   tr.polar_enc_data_out = top_tb.polar_enc_data_out;
   `uvm_info("my_monitor", "encoder out collected", UVM_LOW);

   queue_code.push_back(tr);

endtask
// task my_monitor_out::collect_one_pkt(my_transaction_code tr);
  
// endtask